﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>添加生产领料单行</title>
@*     <link href="//unpkg.com/layui@2.9.21-rc.1/dist/css/layui.css" rel="stylesheet"> *@
</head>
<body>
    <h2>添加生产领料单行</h2>
    <br />
    <form>
        <!-- 文本框 产品物料编码 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><b>产品物料编码</b></label>
            <div class="layui-input-group">
                <input type="text" id="productManageNode" name="productManageNode" placeholder="请选择产品物料编码" class="layui-input">
                <div>
                    <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customsed">
                        <i class="layui-icon layui-icon-search"></i>
                    </button>
                </div>
            </div>
        </div>

        <!-- 文本框 产品物料名称 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><b>产品物料名称</b></label>
            <div class="layui-input-inline">
                <input type="text" id="productManageName" name="productManageName" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 领料数量 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><span style="color:red">*</span><b>领料数量</b></label>
            <div class="layui-input-inline">
                <input id="prodeCount" name="prodeCount" type="number" lay-affix="number" step="1" class="layui-input">
            </div>
        </div>

        <!-- 文本域 规格型号 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><b>规格型号</b></label>
            <div class="layui-input-inline" style="width:500px">
                <textarea name="productManageNumber" id="productManageNumber" class="layui-textarea"></textarea>
            </div>
        </div>

        <!-- 文本框 单位 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><b>单位</b></label>
            <div class="layui-input-inline">
                <input type="text" id="unites" name="unites" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 文本框 批次号 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><b>批次号</b></label>
            <div class="layui-input-inline">
                <input type="text" id="prodLot" name="prodLot" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 文本框 仓库 -->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:90px"><b>仓库</b></label>
            <div class="layui-input-inline">
                <input type="text" id="stashId" name="stashName" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>


        <!-- 文本域 备注 -->
        <div class="layui-form-item">       
            <label class="layui-form-label"><b>备注</b></label>
            <div class="layui-input-inline" style="width:500px">
                <textarea name="remarks" id="remarks" class="layui-textarea"></textarea>
            </div>
        </div>

        <!-- 按钮 -->
        <div class="layui-form-item" style="left:860px">
            <div class="layui-btn-container">
                <button type="button" class="layui-btn layui-bg-blue" lay-submit lay-filter="demo1">确定</button>
                <button type="button" class="layui-btn ">取消</button>
            </div>
        </div>

    </form>

    <!-- HTML Content -->
    @*     <script src="//unpkg.com/layui@2.9.21-rc.1/dist/layui.js"></script> *@
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
            <a class="layui-btn layui-btn-xs" lay-event="YesWang">选择</a>
        </div>
    </script>
</body>
</html>
<script>
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;
    layui.use(function () {
        // 事件
        util.on('lay-on', {
            'test-page-customsed': function () {
                layer.open({
                    type: 1,
                    area: '100%',
                    resize: false,
                    shadeClose: true,
                    title: '库存物资选择',
                    content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="layui-form-item">
                                <div class="demo-Add-container">
                                    <table style="left:320px" class="layui-hide" id="ID-table-demo-datasd" lay-filter="ID-table-demo-datasd"></table>
                                </div>
                            </div>
                        </div>
                    </form>
                    `,
                    success: function () {
                        var form = layui.form;
                        var laypage = layui.laypage;
                        var layer = layui.layer;
                        var $ = layui.$;
                        var laydate = layui.laydate;
                        var util = layui.util;

                        //文档就绪函数
                        $(function () {
                            ProductsSales(1, 2);
                        })

                        //生产报工列表
                        function ProductsSales(pageIndex, pageSize) {
                            let obj = {
                                pageIndex: pageIndex,
                                pageSize: pageSize
                            }
                            var inst = table.render({
                                elem: '#ID-table-demo-datasd',
                                method: 'post',
                                contentType: 'application/json',
                                toolbar: '#toolbarDemo',
                                defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
                                    title: '提示',
                                    layEvent: 'LAYTABLE_TIPS',
                                    icon: 'layui-icon-tips',
                                    onClick: function (obj) { // 2.9.12+
                                        layer.alert('自定义工具栏图标按钮');
                                    }
                                }],
                                url: '@ViewBag.FoundationRead' + '/api/UserLi/SearchMaterial',
                                where: obj,
                                cols: [[
                                    { field: 'productManageNode', title: '产品物料编码', width: 120 },
                                    { field: 'productManageName', title: '产品物料名称', width: 120 },
                                    { field: 'productManageNumber', title: '规格型号', width: 120 },
                                    { field: 'unites', title: '单位', width: 120 },
                                    { field: 'stashName', title: '仓库名称', width: 120 },
                                    { field: 'stickWorkNum', title: '在库数量', width: 80 },
                                    { field: 'stockWorkTime', title: '库存有效期', width: 120 },
                                    { fixed: 'right', title: '操作', width: 140, minWidth: 140, templet: '#toolDemo' }
                                ]],
                                page: false,
                                height: 310,
                                done: function (res) {
                                    var id = this.id;
                                    console.log(res);// 你可以在这里检查返回的数据结构是否符合预期
                                    // 触发单元格工具事件
                                    //分页数据
                                    laypage.render({
                                        elem: 'demo-laypage-alles', // 元素 id
                                        count: res.totalCount, // 数据总数
                                        curr: pageIndex,
                                        limit: pageSize,
                                        limits: [2, 3, 4],
                                        layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                        jump: function (obj, first) {
                                            if (!first) {
                                                ProductionSearch(obj.curr, obj.limit);
                                            }
                                        }
                                    });
                                }
                            })
                            table.on('tool(ID-table-demo-datasd)', function (obj) { // 双击 toolDouble
                                var data = obj.data; // 获得当前行数据
                                console.log(data)
                                if (obj.event === 'YesWang') {
                                    $("#productManageNode").val(data.productManageNode);
                                    $("#productManageName").val(data.productManageName);
                                    $("#unites").val(data.unites);
                                    $("#productManageNumber").val(data.productManageNumber);
                                    //$("#stashName").val(data.stashName);
                                    $("[name='stashName']").val(data.stashName);
                                    $("#prodeCount").val(data.stickWorkNum);
                                    localStorage.setItem("materialNo", data.materialNo);
                                    // localStorage.setItem("stashId", data.stashId);
                                    // 对弹层中的表单进行初始化渲染
                                    form.render();
                                    layer.close(layer.index); // 关闭弹层
                                }
                            });
                        }


                        // 对弹层中的表单进行初始化渲染
                        form.render();
                        // 表单提交事件
                        form.on('submit(demo-Search)', function (data) {
                            var field = data.field; // 获取表单字段值

                            // 显示填写结果，仅作演示用
                            // layer.alert(JSON.stringify(field), {
                            //     title: '当前填写的字段值'
                            // });
                            // 此处可执行 Ajax 等操作
                            // …

                            return false; // 阻止默认 form 跳转
                        });
                    }
                });
            }
        })

        //生产领料单行 新增
        form.on('submit(demo1)', function (data) {
            var datas = {
                productManageNode: $("[name='productManageNode']").val(),  //产品物料编码
                productManageName: $("[name='productManageName']").val(),  //产品物料名称
                productManageNumber: $("[name='productManageNumber']").val(), //规格型号
                unites: $("[name='unites']").val(),  //单位
                prodeCount: $("[name='prodeCount']").val(), //领料数量
                prodLot: $("[name='prodLot']").val(), //批次号
                stashId: localStorage.getItem("stashId"), //仓库
                remarks: $("[name='remarks']").val(), //备注
                pickingNode: localStorage.getItem("pickingNode"), //领料单编号
                prodLineState:1
            };
            console.log(datas);
            $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/ProductType/ProdlinesAdds",
                data: JSON.stringify(datas),
                type: "post",
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    console.log(123, res);
                    if (res.code > 0) {
                        layer.alert("添加成功");
                        layer.closeAll(); // 关闭当前弹层
                    }
                    else {
                        alert('提交失败')
                    }
                }
            })
            //onclick="pinkAdd()"
            // layer.alert(JSON.stringify(field), {
            //     title: '当前填写的字段值'
            // });
            // 此处可执行 Ajax 等操作
            return false; // 阻止默认 form 跳转
        })

    });
</script>
